'use strict';
define(['angular','md5'], function(angular) {
	angular.module('backcenter.updatePassword', [])
//	.config(['$routeProvider', function($routeProvider) {
//		$routeProvider.when('/view1', {
//			templateUrl: 'view1/view1.html',
//			controller: 'View1Ctrl'
//		});
//	}])
	
	.controller('passwordCrtl',['$rootScope', '$scope', function ($rootScope, $scope) {
		
		var Model = this;
		
		//debugger;
		$scope.headerText = 'angularJS运行状态测试：如果您看到这句话，说明angularJS正在运行！';
		
		Model.updatePassword = function(){
			if($scope.passwordOld==null || $scope.passwordOld==''){
				alert('旧密码不能为空！');
				return;
			}
			if($scope.passwordNew==null || $scope.passwordNew==''){
				alert('新密码不能为空！');
				return;
			}

			if($scope.passwordNew!=$scope.passwordConfirm){
				alert('两次输入的新密码不相同，请重新输入！');
				return;
			}
			
//			var sLoginName = document.getElementById('sLoginName').value;
//			console.log('sLoginName-->',sLoginName)
			var data = {
					"sLoginName":$rootScope.sLoginName
			    	,"passwordOld":hex_md5($scope.passwordOld)
			    	,"passwordNew":hex_md5($scope.passwordNew)
			    	};
			
			$.ajax({
	            type: "POST",
	            async : false,//同步执行
	            url: $rootScope.projectName + '/updatePassword',
	            data: JSON.stringify(data),//{'psmID':id},//"{}",
	            contentType: "application/json; charset=utf-8",
//	            dataType: "text",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
					//console.log('data-->',data);
					if(data.code==0){
						document.getElementById('response').innerHTML='保存成功！';
					}else{
						document.getElementById('response').innerHTML='旧密码错误！！';
					}
	            },
	            error: function (msg) {
//					console.log('msg-->',msg);
	                alert('错误信息：ajax调用错误！');
	            }
	        });
			
//			document.getElementById('response').innerHTML='';
			
		};


		///////////////////////////页面级////////////////////////////////////////
		//返回
		Model.goBack = function(event) {
		window.history.go(-1);
		}
		///////////////////////////页面级////////////////////////////////////////

		return Model;

	}]);
	
});
